package com.mq.controller;

import com.mq.bean.Order;
import com.mq.servcie.MyChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by Administrator on 2017/9/1 0001.
 */
@RestController
public class SendController {
    @Autowired
    private MyChannel sender;

    /**
     * 发送订单消息
     * @param oderNum
     * @param number
     * @param type
     * @return
     */
    @PostMapping("/sendOder")
    public String sendOder(String oderNum,String number,String type){
        Order appleOrder = new Order();
        appleOrder.setOrderNum(oderNum);
        appleOrder.setNum(Integer.parseInt(number));
        appleOrder.setType(type);
        appleOrder.setCreateAt(new Date());
        // 使用 注入 MessageChannel 方式发送
        sender.outputOrder().send(MessageBuilder.withPayload(appleOrder).build());
        return "success";
    }
}
